package com.focusai.efairy.model.request;

import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.model.response.CurrentDeviceInfoResponse;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.Request;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

import java.util.Map;

/**
 *
 * 获取当前设备版本信息
 * Created by luo_guangwen on 2017/8/12.
 */

public class GetDeviceVersionInfoRequest extends Request<CurrentDeviceInfoResponse> {
    private String deviceId;   //项目编号

    public GetDeviceVersionInfoRequest(String deviceId, Response.Listener<CurrentDeviceInfoResponse> listener) {
        super(Method.GET, UrlUtils.createUrl("/appapi/device_version"), listener);
        this.deviceId = deviceId;
    }

    @Override
    public Map<String, String> getParams() throws JSONException {
        addParam("efairyuser_id", CacheManager.getUserId());//用户编号
        addParam("access_token", CacheManager.getAccessToken());//令牌
        addParam("efairydevice_id", deviceId);//设备号
        return super.getParams();
    }

    @Override
    protected CurrentDeviceInfoResponse parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<CurrentDeviceInfoResponse>() {
        }.getType());
    }

}
